<template>
  <el-dialog title="账号审核" :visible.sync="dialogVisible" width="30%" :before-close="handleClose">
    <el-form ref="form" :model="form" label-width="100px" label-position="left" :rules="rules">
      <el-form-item label="审核意见：" prop="status">
        <el-radio-group v-model="form.status">
          <el-radio label="1">通过</el-radio>
          <el-radio label="2">驳回</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="驳回原因：" prop="reason" v-show="form.status == '2'" :rules="form.status == '1' ? [] : rules.reason">
        <el-input type="textarea" v-model="form.reason"></el-input>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="handleClose">取 消</el-button>
      <el-button type="primary" @click="Confirm">确 定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  import { auditUesr } from '@/api/user'
  export default {
    data() {
      return {
        dialogVisible: false,
        form: {
          status: '1',
          reason: '',
        },
        rules: {
          status: [{ required: true, message: '请选择审核意见', trigger: 'change' }],
          reason: [{ required: true, message: '请输入驳回原因', trigger: 'blur' }],
        },
      }
    },
    methods: {
      open(row) {
        console.log('row: ', row)
        this.form.id = row.id
        this.dialogVisible = true
      },
      Confirm() {
        console.log(this.form)
        this.$refs.form.validate(async (valid) => {
          if (valid) {
            await auditUesr(this.form).then((data) => {
              if (data.code == 200) {
                this.$message.success('操作成功')
                this.handleClose()
                this.$emit('getList')
              } else {
                this.$message.error(data.msg)
              }
            })
          } else {
            return false
          }
        })
      },
      handleClose() {
        this.form = {
          status: '1',
          reason: '',
        }
        this.dialogVisible = false
      },
    },
  }
</script>

<style></style>
